package me.young.android.fullscreengesture

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast

class SettingsActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setupActionBar()
        supportFragmentManager
                .beginTransaction()
                .replace(android.R.id.content, SettingFragment())
                .commit()
    }

    /**
     * Set up the [android.app.ActionBar], if the API is available.
     */
    private fun setupActionBar() {
        supportActionBar?.setDisplayShowHomeEnabled(true)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        supportActionBar?.setDisplayUseLogoEnabled(true)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.main, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        when (item!!.itemId) {
            R.id.service -> {
                OpenAccessibilitySettingHelper.jumpToSettingPage(this)// 跳转到开启页面
            }
            android.R.id.home -> {
                onBackPressed()
            }
        }
        return super.onOptionsItemSelected(item)
    }

    override fun onResume() {
        super.onResume()
        if (!OpenAccessibilitySettingHelper.isAccessibilitySettingsOn(this,
                        FullScreenAccessService::class.java.name)) {
            OpenAccessibilitySettingHelper.jumpToSettingPage(this)// 跳转到开启页面
            Toast.makeText(this, R.string.open_access_hint, Toast.LENGTH_LONG).show()
        }
    }
}
